home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / mg2a_src.zip / SYS / AMIGA / TTYKBD.C < prev    next >
C/C++ Source or Header  |  1988-08-23  |  3KB  |  132 lines

  1. /*
  2.  * Name:    MG 2a
  3.  *         Amiga virtual terminal keyboard, default console keymap.
  4.  * Created:    Mic Kaczmarczik (mic@emx.cc.utexas.edu)
  5.  * Last edit:    May 14, 1988
  6.  */
  7.  
  8. #undef    TRUE
  9. #undef    FALSE
  10. #include    "def.h"
  11. #include    "kbd.h"
  12.  
  13. /*
  14.  * List of function key names, from KFIRST to KLAST
  15.  */
  16. #ifdef    FKEYS
  17. char    *keystrings[] = {
  18.     "Up",        "Down",        "Left",        "Right",
  19.     "Shift-Up",    "Shift-Down",    "Shift-Left",    "Shift-Right",
  20.     "Help",        "The menu",    "The resize gadget", "The mouse",
  21.     "F1",        "F2",        "F3",        "F4",
  22.     "F5",        "F6",        "F7",        "F8",
  23.     "F9",        "F10",        "Shift-F1",    "Shift-F2",
  24.     "Shift-F3",    "Shift-F4",    "Shift-F5",    "Shift-F6",
  25.     "Shift-F7",    "Shift-F8",    "Shift-F9",    "Shift-F10",
  26.     "Mouse",            "Ctrl-Mouse",
  27.     "Shift-Mouse",            "Shift-Ctrl-Mouse",
  28.     "Meta-Mouse",            "Meta-Ctrl-Mouse",
  29.     "Meta-Shift-Mouse",        "Meta-Shift-Ctrl-Mouse",
  30.     "Mode-Mouse",            "Ctrl-Mode-Mouse",
  31.     "Shift-Mode-Mouse",        "Shift-Ctrl-Mode-Mouse",
  32.     "Meta-Mode-Mouse",        "Meta-Ctrl-Mode-Mouse",
  33.     "Meta-Shift-Mode-Mouse",    "Meta-Shift-Ctrl-Mode-Mouse",
  34.     "Echo-Mouse",            "Ctrl-Echo-Mouse",
  35.     "Shift-Echo-Mouse",        "Shift-Ctrl-Echo-Mouse",
  36.     "Meta-Echo-Mouse",        "Meta-Ctrl-Echo-Mouse",
  37.     "Meta-Shift-Echo-Mouse",    "Meta-Shift-Ctrl-Echo-Mouse"
  38. };
  39. #endif
  40.  
  41. /*
  42.  * Read in a key, doing whatever low-level mapping of ASCII code to
  43.  * 11 bit code.  This has become a bit easier since keymaps.
  44.  */
  45. #define    CSI    0x9b
  46.  
  47. getkbd()
  48. {
  49.     register int c;
  50. #ifdef    FKEYS
  51.     register int    n;
  52. #endif
  53. loop:
  54.     if ((c = ttgetc()) == CSI) {
  55.         c = ttgetc();
  56. #ifdef    FKEYS
  57.         if (c == '?') {            /* HELP key        */
  58.             ttgetc();        /* discard '~'        */
  59.             return (KHELP);
  60.         }
  61.         /* Arrow keys */
  62.         if (c == 'A')
  63.             return (KUP);
  64.         if (c == 'B')
  65.             return (KDOWN);
  66.         if (c == 'C')
  67.             return (KRIGHT);
  68.         if (c == 'D')
  69.             return (KLEFT);
  70.         if (c == 'T')
  71.             return (KSUP);
  72.         if (c == 'S')
  73.             return (KSDOWN);
  74.  
  75.         /* Shifted left, right arrow */
  76.         if (c == ' ') {
  77.             c = ttgetc();
  78.             if (c == 'A' || c == '@')
  79.                 return ((c == 'A') ? (KSLEFT) : (KSRIGHT));
  80.             goto loop;        /* try again, sucker */
  81.         }
  82.  
  83.         /* Function keys    */
  84.         if (c >= '0' && c <= '9') {
  85.             n = 0;
  86.             do {
  87.                 n = 10*n + c - '0';
  88.                 c = ttgetc();
  89.             } while (c>='0' && c<='9');
  90.             if (c == '~' && n < 20)
  91.                 return (n < 9) ? (KF1 + n) : (KSF1 + (n - 10));
  92.             else 
  93.                 goto loop;    /* Try again */
  94.         }
  95. #endif
  96.         goto loop;        /* Try again */
  97.     }
  98.     return (c);
  99. }
  100.  
  101. /*
  102.  * Terminal specific keymap initialization, calling bind() to get
  103.  * things done.  All the keys bound here are done globally.
  104.  */
  105.  
  106. VOID
  107. ttykeymapinit()
  108. {
  109. #ifdef    FKEYS
  110.     KCHAR        c;
  111.     register KEYMAP **mapp = &map_table[0].p_map;
  112. #endif
  113.     static KCHAR    esc_bs[] = { CCHR('['), CCHR('H') };
  114.     static KCHAR    esc_del[] = { CCHR('['), CCHR('?') };
  115.     
  116. #define    BINDC(k,s) (c = k, bindkey(mapp, s, &c, 1))
  117. #define    BINDM(m,s) bindkey(mapp, s, m, (sizeof(m)/sizeof(KCHAR)))
  118.     
  119.     /* Swap the backspace and del keys, at least in normal usage.
  120.      * This loses the help feature of CTRL-H, but we rebind
  121.      * CTRL-_ to do the same thing. Under FKEYS, the Help key
  122.      * calls describe-key-briefly.
  123.      */
  124.     BINDC(CCHR('_'),    "help-help");    /* CTRL-Backspace */
  125.     BINDM(esc_bs,        "backward-kill-word");
  126.     BINDC(CCHR('H'),    "delete-backward-char");
  127.  
  128.     BINDC(CCHR('?'),    "delete-char");
  129.     BINDM(esc_del,        "kill-word");
  130. }
  131.  
  132.